<?php
if (!defined('__FORUMTOOLS_PHP__')) {
define('__FORUMTOOLS_PHP__', ' ');

include '../config.php';

class ForumTools {
	private static	$vInstance = null;

	private	$configs;
	/**
	 * Constructor.
	 */
	private function __construct() {
		$this->configs = array();
	}

	/**
	 * string Get($key)
	 * this method returns any configurations param.
	 * @param $key is the key-name for the configuration param to request.
	 * @return returns the string value or false if it's not found.
	 */
	public static function Get($key) {
		ForumTools::Load();
		$me = ForumTools::Instance();
		return (isset($me->configs[$key])?$me->configs[$key]:false);
	}

	/**
	 * void Load()
	 * This method tries to load all the configurations params.
	 */
	private static function Load() {
		global	$db;
		global	$table_prefix;

		$me = ForumTools::Instance();

		if (!count($me->configs)) {
			connectDataBase();

			$sql = "SELECT	*
				FROM	{$table_prefix}config";

			$res = $db->sql_query($sql);
			while ($row = $db->sql_fetchrow($res)) {
				$me->configs[$row['config_name']] = $row['config_value'];
			}
			$db->sql_freeresult($res);
		}
	}

	/**
	 * ForumTools Instance()
	 * returns the singleton instance for ForumTools. If it doesn't exists,
	 * it will be created here.
	 */
	private static function Instance() {
		if (!ForumTools::$vInstance) {
			ForumTools::$vInstance = new ForumTools();
		}
		return ForumTools::$vInstance;
	}

	/**
	 * string Sitename()
	 * @return returns the site-name.
	 */
	public static function Sitename() {
		return ForumTools::Get('sitename');
	}

	/**
	 * string Description()
	 * @return returns the site description.
	 */
	public static function Description() {
		return ForumTools::Get('site_desc');
	}

	/**
	 * string Link()
	 * @return returns the complete link to refer the forum.
	 */
	public static function Link() {
		$out = ForumTools::Get('server_protocol');
		$out.= ForumTools::Get('server_name');
		$aux = ForumTools::Get('server_port');
		$out.= ($aux&&$aux!='80'?":$aux":'');
		$aux = ForumTools::Get('script_path');
		$out.= ($aux?$aux:'/');
		return $out;
	}

	/**
	 * string Link()
	 * @param $data
	 * @param $isBB
	 * @return returns the complete link to refer the forum.
	 */
	public static function AdaptString($data, $isBB=false) {
		if ($isBB && is_array($data)) {
		}

		$data = str_replace('&', '&amp;', $data);

		return $data;
	}
};

} // __FORUMTOOLS_PHP__ //
?>